myApp.controller('ProjectListController', function ($scope, $stateParams, $http) {
    //工程列表
    $scope.list=[];
    $scope.count=0;
    $scope.total=$scope.list.length;

    $scope.page = {size: 10, index: 1}; 


    $http.post(java_url+'/beetle/project/projectInfoList',{
        isShowJar:true,
        tokenId:getTokenId()
    }).success(function(data){
        if (data.code == '2') {
            window.location.href = "/beetle/App/module/login/tpl/login.html";
            return;
        } else if (data.code != '0') {
            alert("获取工程列表失败!desc:" + data.desc);
            return;
        };
        $scope.list=data.data.list;
        angular.forEach($scope.list,function (pro) {
            if($scope.isTrunk(pro.projectName)){
                pro.trunkName = pro.projectName;
            }else{
                pro.trunkName = pro.projectName.split('_')[0];
            }
        });
        $scope.count=$scope.list.length;
    });

    $scope.edit = function(projectName){
        if($scope.isTrunk(projectName)){
            window.location.href = "#/menu/projectEdit/"+projectName+"/0/";
        }else{
            window.location.href = "#/menu/projectEdit/"+projectName+"/1/";
        };
    };

    $scope.del = function(projectName){
        if (confirm("删除的工程无法恢复(包括已经构建好的文件和配置信息),确认删除?")) {
            $http.post(java_url+'/beetle/project/delProject',{
                projectName:projectName,
                tokenId:getTokenId()
            }).success(function(data){
                if (data.code == '2') {
                    window.location.href = "/beetle/App/module/login/tpl/login.html";
                    return;
                };
                alert(data.desc);
                var href = "#/menu/projectSet/";
                reload(href);
            });
        };
    };

    $scope.add = function(){
        window.location.href = "#/menu/projectEdit///";
    };

    $scope.isTrunk = function(projectName){
        if(projectName.indexOf("_") != -1){
            return false;
        }else{
            return true;
        };
    };
});